<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]-->
    <script type="text/javascript" src="../../../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../../../lib/respond.min.js?rev=@@hash"></script>
    <!--[endif]-->
    <link rel="stylesheet" type="text/css" href="../../../../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../../../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../../../../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../../../../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../../../../static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../../../ht-css/Project.css" />
    <link rel="stylesheet" type="text/css" href="../../../../ht-css/style-q.css" />
    <!--[if IE 6]-->
    <script type="text/javascript" src="../../../../lib/DD_belatedPNG_0.0.8a-min.js?rev=@@hash"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <!--[endif]-->
    <title>编辑兑换商品</title>
</head>
<body>
<nav class="breadcrumb">首页 <span class="c-gray en">&gt;积分管理 <span class="c-gray en">&gt;</span> <span onclick="returnVer()" style="cursor: pointer">积分商城</span><span class="c-gray en">&gt;</span> 积分活动管理&gt;</span> 编辑兑换商品<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px ;display:block" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container">
    <form class="ml-20 mr-20" id="appVersionForm"  method="post">
        <div class="bk-gray bg-1 pd-20 text-c">
            <div class="va-m lh-20 f-14 pb-15">
                <strong style="margin-left: -341px;">基础信息</strong>
            </div>
            <table class="table mt-10 col-2-1" style="margin-left: 35%">

                <tbody>

                <tr>
                    <td>
                        <div>
                            <label class="form-label f-l w-85 text-r lh-26" style="width: 97px;margin-left: -12px;"><em class="c-red mr-5">*</em>当前状态：</label>
                            <span class="radius f-l ml-10" id="activityStatus"></span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div>
                            <label class="form-label f-l w-85 text-r lh-26"><em class="c-red mr-5">*</em>商品名称：</label>
                            <span class=" radius f-l ml-10" id="codes"></span>
                            <span class=" radius f-l ml-10" id="names"></span>
                            <input id="nameButto"  type="button" class="btn btn-secondary  radius f-l ml-10" onclick="choicePic()" value="更换">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div style="width: 614px;">
                            <label class="form-label f-l w-85 text-r lh-26">活动描述：</label>
                            <textarea style=" max-width: 500px;" class="textarea" oninput="checkMaxIut(this)" id="productDetail"  placeholder="请输入描述" ></textarea><br>
                        </div>
                    </td>
                    <td >
                        <div class="row clearfix">
                            <div class="formControls w-700 f-l" style=" margin-top: 73px;width: 50px">
                                <span id="textSpan">0</span>/<span id="commonText"></span>
                            </div>
                        </div>

                    </td>
                </tr>
                <tr>
                    <td>
                        <div>
                            <label class="form-label f-l w-85 text-r lh-26"><em class="c-red mr-5">*</em>可兑换积分：</label>
                            <input type="text" class="input-text radius f-l ml-10" id="useIntegralNum" name="fileName" style="width: 39%; margin-left: 18px"   autocomplete="off" maxlength="7" oninput="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">

                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div>
                            <label class="form-label f-l w-85 text-r lh-26" style="width: 97px;margin-left: -12px;"><em class="c-red mr-5">*</em>兑换商品数量：</label>
                            <input type="text" class="input-text radius f-l ml-10" id="productCount" name="fileName" style="width: 39%; margin-left: 18px"   autocomplete="off" maxlength="7" oninput="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div>
                            <label class="form-label f-l w-85 text-r lh-26"><em class="c-red mr-5">*</em>生效时间：</label>
                            <div class="f-l ml-10">
                                <input onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'timemax\')}',startDate:'%y-%M-%d 00:00',dateFmt:'yyyy-MM-dd HH:mm:59',alwaysUseStartDate:true})" class="input-text Wdate radius" id="timemin" type="text" placeholder="起始时间" style="width:144px;margin-left: 9px;"  autocomplete="off" readonly>
                                ~
                                <input onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'timemin\')}',dateFmt:'yyyy-MM-dd HH:mm:59'})" class="input-text Wdate radius" id="timemax" type="text" placeholder="结束时间" style="width:144px;" autocomplete="off" readonly>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div>
                            <label class="form-label f-l w-85 text-r lh-26" style="width: 97px;margin-left: -11px;">创建时间：</label>
                            <span id="createTime" class="radius f-l ml-10" style="margin-left: 18px;"></span>
                        </div>
                    </td>
                    <td>
                        <div style="margin-left: -254px;">
                            <label class="form-label f-l w-85 text-r lh-26" style="width: 97px;margin-left: -12px;">操作人：</label>
                            <span id="createPerson" class=" radius f-l ml-10"></span>
                        </div>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <div style="display: none" id="updateTimes" >
                            <label class="form-label f-l w-85 text-r lh-26" style="width: 97px;margin-left: -11px;">最后更改时间：</label>
                            <span id="updateTime" class="radius f-l ml-10" style="margin-left: 18px;"></span>
                        </div>
                    </td>
                    <td>
                        <div style="margin-left: -254px;display: none" id="updatePersons">
                            <label class="form-label f-l w-85 text-r lh-26" style="width: 97px;margin-left: -12px;">操作人：</label>
                            <span id="updatePerson"  class=" radius f-l ml-10"></span>
                        </div>
                    </td>
                    <td></td>
                </tr>

                </tbody>
            </table>

            <div class="text-c mt-10">
                <input type="button" class="btn btn-secondary radius size-S" value="确认" onclick="add()">
                <input type="button" class="btn radius size-S ml-10" value="取消" onclick="returnVer()">
            </div>
        </div>
    </form>


</article>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../../../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../static/h-ui/js/H-ui.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../static/h-ui.admin/js/H-ui.admin.js?rev=@@hash"></script> <!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<script src="../../../../ht-js/frame/doT.min.js?rev=@@hash"></script>
<script src="../../../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../../../ht-js/verifyToken.js?rev=@@hash"></script>
<script src="../../../../ht-js/Project.js?rev=@@hash"></script>
<script src="../../../../ht-js/operation-js/operation_activity/activity_login.js?rev=@@hash"></script>
<script src="../../../../ht-js/contract/jquery-form.js?rev=@@hash"></script>

<link type="text/css" rel="stylesheet" href="../../../../ht-js/operation-js/time-js/jedate.css">
<script type="text/javascript" src="../../../../ht-js/operation-js/time-js/jquery.jedate.js?rev=@@hash"></script>
<script>
    function returnVer(){
        var curInd = layer.confirm(
            '<span>返回则无法保存当前更新内容</span>'+'<br/>', {title:'提示',btn: ['确定', '取消']}, function(index){
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                layer.close(curInd);

            },function(){
                layer.close(curInd);

            });
    }
    var ids=sessionStorage.getItem("id")
    //查询
    editing()
    function editing() {
        $.ajax({
            url:root.integralManagement.searchIntegralActivity,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "id":ids
            }),
            success: function (data) {
                if(data.errorCode==0){


                    if(data.data.activityStatus==10){
                        $("#activityStatus").html("进行中")
                    } else if(data.data.activityStatus==20){
                        $("#activityStatus").html("未生效")
                    }else if(data.data.activityStatus==30){
                        $("#activityStatus").html("已结束")
                    }else if(data.data.activityStatus==40){
                        $("#activityStatus").html("已禁用")
                    }
                    $("#codes").html(data.data.integralProductCode)
                    $("#names").html(data.data.skuName)
                    $("#useIntegralNum").val(data.data.useIntegralNum)
                    $("#productCount").val(data.data.productTotal)
                    $("#productDetail").val(data.data.productDetail)
                    $("#timemin").val(data.data.startTime)
                    if(data.data.endTime=="1001-01-01 00:00:00"){
                        $("#timemax").val("")
                    }else {
                        $("#timemax").val(data.data.endTime)
                    }

                    $("#createTime").html(data.data.createTime)
                    $("#createPerson").html(data.data.createPerson)

                    if(data.data.updateTime!=""&&data.data.updateTime!=null){
                        $("#updateTime").html(data.data.updateTime)
                        $("#updatePerson").html(data.data.updatePerson)

                        $("#updateTimes").css({
                            display: "inline"
                        });
                        $("#updatePersons").css({
                            display: "block"
                        });
                    }

                    //渲染限制字符
                    var kk=$("#productDetail").val()
                    var ss= kk.replace(/[\u0391-\uFFE5]/g,"aa").length;
                    $("#textSpan").html(ss)
                }else {

                    $.Huimodalalert(data.msg,2000);

                }
            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        })
    }

    //限制字符
    var len
    var Preser
    var common=100//要限制输入的字数
    $('#commonText').text(common)
    function checkMaxIut(me) {
        var text=$(me).val()
        strlen(text)
        if(len>common){
            $(me).val(Preser)
        }else {
            Preser=$(me).val()
        }
    }
    function strlen(str){
        len = 0;
        for (var i=0; i<str.length; i++) {
            var c = str.charCodeAt(i);
            //单字节加1
            if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
                len++;
            } else {
                len+=2;
            }
        }
        $('#textSpan').text((len>100)?100:len)
        return len;
    }
    //选择商品
    function choicePic() {
        layer_show("搜索商品","chooseCommodity.html","1024","500","215","100");
    }
    function Rendering(){
        $("#codes").html(sessionStorage.getItem("codes"))
        $("#names").html(sessionStorage.getItem("names"))
    }

    function add() {
        if($("#codes").html()==""){
            $.Huimodalalert('请填写商品名称',2000);
            return false;
        }
        if($("#useIntegralNum").val()==""){
            $.Huimodalalert('请填写可兑换积分',2000);
            return false;
        }
        if($("#productCount").val()==""){
            $.Huimodalalert('请填写兑换商品数量',2000);
            return false;
        }
        if($("#timemin").val()==""){
            $.Huimodalalert('请选择生效时间',2000);
            return false;
        }
        $.ajax({
            url:root.integralManagement.updateIntegralActivity,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "id":ids,
                "integralProductCode":$("#codes").html(),
                "productDetail":$("#productDetail").val(),
                "useIntegralNum":$("#useIntegralNum").val(),
                "productTotal":$("#productCount").val(),
                "startTime":$("#timemin").val(),
                "endTime":$("#timemax").val(),
                "createPerson":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                "updatePerson":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
            }),
            success: function (data) {
                if(data.errorCode==0){
                    if(data.sub_code==1){
                        $.Huimodalalert('商品总数量不可低于可用数量',2000);
                    }else {
                        layer.msg("编辑成功",{icon: 6,time:1000},function () {
                            parent.location.reload(); // 父页面刷新
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);
                        });
                    }


                }else {

                    $.Huimodalalert(data.msg,2000);

                }
            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        })
    }
</script>
</body>
</html>